import { Controller, Post, Get,Param, ParseIntPipe,Request,Body ,BadRequestException, Delete, Query, Response } from '@nestjs/common';
import { success } from '@/utils';
import { SpecsService  } from './specs.service';
@Controller('specs')
export class SpecsController {
    constructor(private readonly specsService: SpecsService) {}
    @Post('listBy')
    async listBy(@Body() info:any,@Request() req:any) {
      if(info==undefined||!info.admins_id)info['admins_id'] = req.user.user.id
        try {   
          const res = await this.specsService.specsBypage(info)
          return success(res, '获取成功');
        } catch (error) {
            throw new BadRequestException('参数不正确');
        }
    }
    @Post('editBy')
    async editBy(@Body() info:any,@Request() req:any) {
        try { 
          if(info.id){
            var res = await this.specsService.editspecs(info)
          }else{
            if(!info.admins_id)info['admins_id'] = req.user.user.id
            var res = await this.specsService.addspecs(info)
          }
          return success(res,info.id?'修改成功':'获取成功');
        } catch (error) {
            throw new BadRequestException('参数不正确');
        }
    }
    @Get('/detail/:id')
    async detail(@Param('id',ParseIntPipe) id:number) {
      try { 
        const res = await this.specsService.oneMenu(id)
        return success(res, '获取成功');
      } catch (error) {
          throw new BadRequestException('参数不正确');
      }
    }
    @Delete('Del')
    async Del(@Query('id',ParseIntPipe) id:number) {
      try { 
        const res = await this.specsService.delete(id)
        return success(res, '删除成功');
      } catch (error) {
          throw new BadRequestException('参数不正确');
      }
    }
}
